﻿@page "/comments"
@page "/comments/pages"
@page "/comments/pages/{pageNumber:int}"
@inject NotificationService NotificationService
@inherits BaseCommentPage

<PageContainer Title="Comments" PageTitle="@Title">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>
                <a href="">
                    <MdiIcon Type="@IconNames.Home" />
                    <span>Home</span>
                </a>
            </BreadcrumbItem>
            <BreadcrumbItem>
                <span>
                    <MdiIcon Type="@IconNames.Comment" />
                    <span>Comments</span>
                </span>
            </BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <ChildContent>
        <Loader OnLoad="@OnLoad" LoadKey="@($"{PageNumber}")" @ref="loader">
            <PagingList Data="@Data" Column="1" PageNavigationUrl="@UrlGenerator.Comments()">
                <ItemTemplate>
                    <CommentListItem Id="@context" ShowSource="@true"></CommentListItem>
                </ItemTemplate>
            </PagingList>
        </Loader>
    </ChildContent>
</PageContainer>

@code {
    const int PageSize = 10;

    PagingData<string> Data { get; set; }

    [Parameter]
    public int? PageNumber { get; set; } = null;

    private Loader loader;

    private async Task OnLoad()
    {
        Title = "Loading...";
        Data = await Service.CommentService.QueryPaging(new CommentQueryRequest
        {
            Order = QueryTimeOrder.CreationTimeDescending,
            Pagination = new Data.Models.Actions.Pagination
            {
                CurrentPage = PageNumber ?? 0,
                PageSize = PageSize
            }
        });
        Title = $"Page {Data.CurrentPage.CurrentPage + 1}";
    }
}
